﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows;
using HalconDotNet;

namespace TestHObject2BitMap
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        HObject hoImage;
        YsHObject2Bitmap.HObject2Bitmap ysHobject2Bitmap = new YsHObject2Bitmap.HObject2Bitmap();
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "图片文件|*.bmp;*.jpg;*.jpeg;*.tif";
            dialog.Title = "打开文件";

            byte[] testByte = null;
            if (dialog.ShowDialog()== System.Windows.Forms.DialogResult.OK)
            {



                HOperatorSet.ReadImage(out hoImage, dialog.FileName);

                if (pictureBox1.Image != null)
                {
                    pictureBox1.Image.Dispose();
                }

                //测试 Bitmap
               pictureBox1.Image = ysHobject2Bitmap.GetBitmapSource(hoImage);

                //测试 byte[]
            //   testByte = ysHobject2Bitmap.GetBitmap(hoImage);

                if (hoImage != null && hoImage.IsInitialized())
                {
                    hoImage.Dispose();
                }


            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }
    }
}
